<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="java.sql.*" %>
<% 
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
application.setAttribute("url",basePath);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <%!
		class UploadList{
			int id;
			int userid;
			String username;
			String name;
			String datetime;
			String detail;
			boolean hidden;
			int count;
			String file;
		}
	%>
    <title>主页|银光云-为银光字幕组提供最优质的云存储服务 - Powered by 金鸡独立</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<%
		UploadList[] ul=null;
		Class.forName("com.mysql.jdbc.Driver");
		Connection con=DriverManager.getConnection((String) application.getAttribute("dburl"),(String) application.getAttribute("username"),(String) application.getAttribute("password"));
 		Statement s=con.createStatement();
 		Statement s1=con.createStatement();
		String sqls1="SELECT * FROM data WHERE hidden=FALSE";
		ResultSet rs=s.executeQuery(sqls1);
		rs.last();
		int len=rs.getRow();
		rs.beforeFirst();
		if(len>0){
			ul=new UploadList[len];
			for(int i=0;i<len;++i) ul[i]=new UploadList();
			rs.next();
			for(int i=0;i<len;++i){
				ul[i].id=rs.getInt(1);
				ul[i].userid=rs.getInt(2);
				ul[i].name=rs.getString(3);
				if(ul[i].name.length()>15) ul[i].name=ul[i].name.substring(0,16)+"……";
				ul[i].datetime=rs.getString(4);
				ul[i].detail=rs.getString(5);
				if(ul[i].detail.length()>15) ul[i].detail=ul[i].detail.substring(0,16)+"……";
				ul[i].hidden=rs.getBoolean(6);
				ul[i].count=rs.getInt(7);
				ul[i].file=rs.getString(8);
				if(ul[i].file.length()>15) ul[i].file=ul[i].file.substring(0,16)+"……";
				rs.next();
				String sqls2="SELECT name FROM user WHERE id="+ul[i].userid;
				ResultSet rs1=s1.executeQuery(sqls2);
				if(rs1==null){
					out.println("致命错误-0006：无法在数据库中找到username！请联系QQ2276768747以解决问题。");
					return ;
				}
				rs1.next();
				ul[i].username=rs1.getString(1);
			}
		}
	%>
</head>
  
<body>
<center>
<h1><font color="red">银光字幕组专属云-主页</font></h1>
<table>
	<tr>
		<td><a href="/SilverCould/index.jsp">返回主页</a></td>
		<td>
			<form action="/SilverCould/page/search.jsp" method="get">
				<input type="text" id="keyword" name="keyword" style="width: 350px">
				<input type="submit" value="搜索">
			</form>
		</td>
	</tr>
</table>
<br/>
资源完全列表：
<%if(ul!=null){ %>
共有<%=len %>条记录：
<br/>
<table border="1">
	<tr>
		<th>编号</th>
		<th>标题</th>
		<th>上传者</th>
		<th>上传时间</th>
		<th>简介</th>
		<th>访问次数</th>
		<th>文件名</th>
		<th>链接</th>
	</tr>
	<%
		for(int i=0;i<len;++i){
			out.println("<tr>");
			out.println("	<td>"+ul[i].id+"</td>");
			out.println("	<td>"+ul[i].name+"</td>");
			out.println("	<td>"+ul[i].username+"</td>");
			out.println("	<td>"+ul[i].datetime+"</td>");
			out.println("	<td>"+ul[i].detail+"</td>");
			out.println("	<td>"+ul[i].count+"</td>");
			out.println("	<td>"+ul[i].file+"</td>");
			out.println("	<td><a href=\"page/watch.jsp?id="+ul[i].id+"\">进入播放和下载页面</a></td>");
			out.println("</tr>");
		}
	%>
</table>
<%}else{ %>
<font color="red">还未上传资源</font>
<%} %>
</center>
</body>
</html>
